package day02;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args) {
        System.out.println("-----------------------------集合正常输出--------------------");
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("a");
        list.add("a");
        list.add("a");
        System.out.println(list);

        System.out.println("-----------------------------集合使用Hashset去重--------------------");
        ArrayList<String> list1 = new ArrayList<>((new HashSet<String>(list)));
        System.out.println(list1);


        System.out.println("-----------------------------hashset普通输出--------------------");
        //1.创建hashset对象
        HashSet<String> hs = new HashSet<>();
        //2.保存数据,同一数据只能保存一份，可用于去重
        hs.add("a");
        hs.add("b");
        hs.add("c");
        hs.add("d");

        System.out.println(hs);

        System.out.println("-----------------------------hashset迭代器输出--------------------");
        //3.取数据（迭代器）
        Iterator<String> it = hs.iterator();
        while (it.hasNext()) {
            String next = it.next();
            System.out.println(next);
        }

        //4.增强for循环
        System.out.println("-----------------------------增强for--------------------");
        for (String s : hs) {
            System.out.println(s);
        }

        //5.lambda表达式
        System.out.println("-----------------------------lambda111--------------------");
        hs.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        System.out.println("-----------------------------lambda222-------------------");
        hs.forEach(s -> System.out.println(s) );

        System.out.println("-----------------------------lambda333--------------------");
        hs.forEach(System.out::println);

        Student student = new Student("老铁",28);
        System.out.println(student);


    }
}
